package cn.springboot.pioneermall.api.chat;


import cn.springboot.pioneermall.core.controller.BaseController;
import cn.springboot.pioneermall.core.domain.AjaxResult;
import cn.springboot.pioneermall.core.page.TableDataInfo;
import cn.springboot.pioneermall.robotChat.domain.HsChatAskAnswerTemplate;
import cn.springboot.pioneermall.robotChat.service.IHsChatAskAnswerTemplateService;
import cn.springboot.pioneermall.util.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 客服问答模板Controller
 *
 * @author ljxl
 * @date 2023-10-21
 */
@RestController
@RequestMapping("/manage-api/v1")
public class HsChatAskAnswerTemplateController extends BaseController {
    @Autowired
    private IHsChatAskAnswerTemplateService hsChatAskAnswerTemplateService;


    /**
     * 查询客服问答模板列表
     */
    @GetMapping("/robotChat/list")
    public TableDataInfo list(HsChatAskAnswerTemplate hsChatAskAnswerTemplate) {
        startPage();
        List<HsChatAskAnswerTemplate> list = hsChatAskAnswerTemplateService.selectHsChatAskAnswerTemplateList(hsChatAskAnswerTemplate);
        return getDataTable(list);
    }

    /**
     * 导出客服问答列表
     */
    @GetMapping("/robotChat/export")
    public AjaxResult export(HsChatAskAnswerTemplate hsChatAskAnswerTemplate) {
        List<HsChatAskAnswerTemplate> list = hsChatAskAnswerTemplateService.selectHsChatAskAnswerTemplateList(hsChatAskAnswerTemplate);
        ExcelUtil<HsChatAskAnswerTemplate> util = new ExcelUtil<HsChatAskAnswerTemplate>(HsChatAskAnswerTemplate.class);
        return util.exportExcel(list, "askAnswerTemplate");
    }

    /**
     * 获取客服问答模板详细信息
     */
    @GetMapping(value = "/robotChat/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(hsChatAskAnswerTemplateService.selectHsChatAskAnswerTemplateById(id));
    }

    /**
     * 新增客服问答模板
     */

    @PostMapping("/robotChat/add")
    public AjaxResult add(@RequestBody HsChatAskAnswerTemplate hsChatAskAnswerTemplate) {
        return toAjax(hsChatAskAnswerTemplateService.insertHsChatAskAnswerTemplate(hsChatAskAnswerTemplate));
    }

    /**
     * 修改客服问答模板
     */

    @PutMapping("/robotChat/modify")
    public AjaxResult edit(@RequestBody HsChatAskAnswerTemplate hsChatAskAnswerTemplate) {
        return toAjax(hsChatAskAnswerTemplateService.updateHsChatAskAnswerTemplate(hsChatAskAnswerTemplate));
    }

    /**
     * 删除客服问答模板
     */

    @DeleteMapping("/robotChat/delete/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(hsChatAskAnswerTemplateService.deleteHsChatAskAnswerTemplateByIds(ids));
    }

    /**
     * 导入excle数据
     * @param file 导入文件
     * @return
     * @throws Exception 抛出异常
     */
    @PostMapping("/robotChat/importData")
    public AjaxResult importData(
            MultipartFile file
    ) throws Exception {
        ExcelUtil<HsChatAskAnswerTemplate> excelUtil = new ExcelUtil<>(HsChatAskAnswerTemplate.class);
        List<HsChatAskAnswerTemplate> hsChatAskAnswerTemplates = excelUtil.importExcel(file.getInputStream());
        String s = hsChatAskAnswerTemplateService.importHsAskAnswerTemplate(hsChatAskAnswerTemplates);
        return AjaxResult.success(s);
    }

    /**
     * 问答模板下载
     * @return
     */
    @GetMapping("/robotChat/downloadTemplate")
    public AjaxResult getTemplate() {
        ExcelUtil<HsChatAskAnswerTemplate> excelUtil = new ExcelUtil<>(HsChatAskAnswerTemplate.class);
        return excelUtil.importTemplateExcel("问答模板");

    }


}
